{% load static %}
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>REJECT</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        #zhongbao_create_html{
            width: 250px;
            margin: 0 auto;
        }

        #zhongbao_reject_submit {
            background-color: #ea0808;
            border: none;
            color: white;
            padding: 8px 23px;
            text-align: center;
            text-decoration: none;
            display: inline-block;
            font-size: 16px;
            margin: 4px 2px;
            cursor: pointer;
        }
    </style>
</head>
<body>
<div id="zhongbao_create_html">
    <ul id="zhongbao_cvalue_list" style="list-style:none;display: inline;">
        <li>
            任务ID：
            <input type="text" name="zhongbao_task_id" value="{{ task_id }}" disabled="disabled">
        </li>
        <li>
            <input type="checkbox" name="zhongbao_cvalue" value="title错误" style="-webkit-appearance: checkbox;">
            title错误
        </li>
        <li>
            <input type="checkbox" name="zhongbao_cvalue" value="source错误" style="-webkit-appearance: checkbox;">
            source错误
        </li>
        <li>
            <input type="checkbox" name="zhongbao_cvalue" value="retweeted_source错误"
                   style="-webkit-appearance: checkbox;">
            retweeted_source错误
        </li>
        <li>
            <input type="checkbox" name="zhongbao_cvalue" value="content错误" style="-webkit-appearance: checkbox;">
            content错误
        </li>
        <li>
            <input type="checkbox" name="zhongbao_cvalue" value="content_xml错误" style="-webkit-appearance: checkbox;">
            content_xml错误
        </li>
        <li>
            <input type="checkbox" name="zhongbao_cvalue" value="pic_url错误" style="-webkit-appearance: checkbox;">
            pic_url错误
        </li>
        <li>
            <input type="checkbox" name="zhongbao_cvalue" value="ctime错误" style="-webkit-appearance: checkbox;">
            ctime错误
        </li>
        <li>
            <input type="checkbox" name="zhongbao_cvalue" value="siteName错误" style="-webkit-appearance: checkbox;">
            siteName错误
        </li>
        <li>
            <input type="checkbox" name="zhongbao_cvalue" value="10天无数据" style="-webkit-appearance: checkbox;">
            10天无数据
        </li>
        <li>
            <input type="checkbox" name="zhongbao_cvalue" value="channel错误" style="-webkit-appearance: checkbox;">
            channel错误
        </li>
        <li>
            <input type="checkbox" name="zhongbao_cvalue" value="漏采" style="-webkit-appearance: checkbox;">
            漏采
        </li>
        <li>
            其他
            <input type="text" name="zhongbao_cvalue" value="" id="other_cvalue">
        </li>
    </ul>
    <button id="zhongbao_reject_submit" onclick="reject('{{test_url}}')">
        提交
    </button>
</div>
</body>
</html>

<script src="{% static 'plugins\jQuery\jquery-2.2.3.min.js' %}"></script>

<script type="text/javascript">

    var input_task_id = $("input[name='zhongbao_task_id']").val();
    if (!input_task_id) {
        $("input[name='zhongbao_task_id']").removeAttr("disabled");
        $("input[name='zhongbao_task_id']").attr("placeholder", "没有查询到任务ID，请手动输入...");
    }

    function reject(test_url) {

        // 获取选中复选框的值
        var ids = "";
        $('input[name="zhongbao_cvalue"]:checked').each(function () {
            ids += $(this).val() + ',';
        });//得到选中复选框的value

        var other_cvalue = $('#other_cvalue').val();

        //去掉最后一个“，”号
        var textStr = '测试链接：' + test_url + ' 错误字段：' + ids.substring(0, ids.lastIndexOf(",")) + other_cvalue;

        var task_id = $("input[name='zhongbao_task_id']").val();

        $.ajax(
            {
                url: "{% url 'task:reject' %}",
                type: "POST",
                dataType: "json",
                data: {'csrfmiddlewaretoken': '{{ csrf_token }}', 'tids': task_id, 'cvalue': textStr},
                success: function (result) {
                    alert(result.message);
                    window.close();
                },
                error: function (xhr, status, p3, p4) {
                    var err = "Error " + " " + status + " " + p3;
                    if (xhr.responseText && xhr.responseText[0] == "{")
                        err = JSON.parse(xhr.responseText).message;
                    alert(err + '不合格状态修改失败！！！请点击重新修改');
                }
            });

    }

</script>